package domain;

import java.sql.Timestamp;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "Ofertas")
public class Offer extends PersistentEntity implements Comparable<Offer>{
	private double offerPrice;
	@ManyToOne
	private User user;
	private Timestamp date;
	
	public Offer(){
	}

	public Offer(User user, double offerPrice, Timestamp date){
		this.user=user;
		this.offerPrice=offerPrice;
		this.date=date;
	}
	
	public boolean offeredMore(Offer of){
		return this.offerPrice>=of.getOfferPrice();
	}
	
	public double getOfferPrice(){
		return this.offerPrice;
	}
	
	public Timestamp getDate(){
		return this.date;
	}
	
	public User getUser(){
		return this.user;
	}

	@Override
	public int compareTo(Offer o) {
		return new Double(o.offerPrice).compareTo(new Double(offerPrice));
	}
}
